﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <!-- Add link to template library connector settings page from doc lib settings -->
  <CustomAction
		Id="Microsoft.SharePoint.ListEdit.DocumentLibrary.GeneralSettings"
		RegistrationId="101"
		RegistrationType="List"
		GroupId="GeneralSettings"
		Location="Microsoft.SharePoint.ListEdit.DocumentLibrary"
		Title="Template Library Connector Settings"
		Description="Select another library to serve as the template source for this library"
		Rights="ManageLists">
    <UrlAction Url="_layouts/TemplateHub/TemplateLibraryConnectorConfig.aspx?List={ListId}"/>
  </CustomAction>

  <!-- Replace the standard "New Document" button with the "New from template" button -->
  <CustomAction Id="TemplateSelectorButton"
    Location="CommandUI.Ribbon"
    RegistrationId="101"
    RegistrationType="List">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Documents.New.Controls._children">
          <Button
            Id="Ribbon.Documents.New.Controls.TemplateSelectorButton"
            Alt="Select template"
            Sequence="13"
            Image16by16="/_layouts/1033/Images/formatmap16x16.png" Image16by16Top="-216" Image16by16Left="-32"
            Image32by32="/_layouts/1033/Images/formatmap32x32.png" Image32by32Top="-160" Image32by32Left="-96"
            Command="ShowSelectorCommand"
            LabelText="$Resources:TemplateLibraryConnector,NewFromTemplateButton;"
            TemplateAlias="o1"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="ShowSelectorCommand"
          CommandAction="javascript: { var options = { url: L_Menu_BaseUrl  + '/_layouts/TemplateHub/Selector.aspx', width: 1000,  height: 500, dialogReturnValueCallback: Function.createDelegate(null, function(result, returnValue) { if(result != SP.UI.DialogResult.OK) { SP.UI.ModalDialog.RefreshPage(result); } else { window.onfocus=RefreshOnFocus; }})}; SP.UI.ModalDialog.showModalDialog(options); }; " />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

</Elements>
